#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdbool.h>

struct TreeNode {
    int val;
    struct TreeNode* left;
    struct TreeNode* right;
};

//bool isUnivalTree(struct TreeNode* root) {
//    if (root == NULL)
//        return true;
//    if (root->left == NULL && root->right == NULL)
//        return true;
//    else if (root->left || root->right == NULL)
//        return root->val == root->left->val;
//    else if (root->right || root->left == NULL)
//        return root->val == root->right->val;
//    else
//        return (root->val == root->left->val) && (root->val == root->right->val);
//    return isUnivalTree(root->left) && isUnivalTree(root->right);
//}

bool isUnivalTree(struct TreeNode* root) {
    if (root == NULL)
        return true;
    if (root->left)
    {
        if (root->val != root->left->val || !isUnivalTree(root->left))
            return false;
    }
    if (root->right)
    {
        if (root->val != root->right->val || !isUnivalTree(root->right))
            return false;
    }
    return true;
}